#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;
/*
 When solving problem, don't take anything for granted.
 Only if the conditions were met, we would do it.
 Notice the branch of "with parent" is handled in parent node,
 and the branch of "without parent" is handled by itself.
 */
int n, m;
int head[N];
int ver[N << 1], Next[N << 1], tot;
void add(int u, int v) {
  ++tot;
  ver[tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
int vis[N], sz[N], ans = -1;
void dfs(int u, int fu) {
  vis[u] = 1;
  sz[u] = 0;
  vector<int> a;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    dfs(v, u);
    if (sz[v] > 1) ans = max(ans, sz[v] + 1);  // with parent
    a.push_back(sz[v]);
  }
  sort(a.begin(), a.end(), greater<int>());
  if (a.size() >= 4)
    ans = max(ans, 1 + a[0] + a[1] + a[2] + a[3]);  // without parent
  if (a.size() >= 3) {
    sz[u] = 1 + a[0] + a[1] + a[2];
  } else {
    sz[u] = 1;
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 2, n) {
    int u, v;
    cin >> u >> v;
    add(u, v), add(v, u);
  }
  rep(i, 1, n) if (!vis[i]) dfs(i, i);
  cout << ans;
  return 0;
}